//深度复制对象或者数组
function deepCopy(object) {
  let newArr = Array.isArray(object)?[]:{}
  for (let key in object) {
    
    if(typeof object[key]!=="object"){
      newArr[key] = object[key]
    }else{
      newArr[key]= deepCopy(object[key])
    }
    // let arr2 = typeof object[key]==="object"?deepCopy(object[key]):object[key]
    // newArr[key] = arr2
  }
   return newArr;
}

let a = {
  d:3,
  b:{
    c:2
  }
}
let b = deepCopy(a)
a.b.c=4
console.log(JSON.stringify(a));
console.log(JSON.parse( JSON.stringify(a)));
console.log(a);
console.log(b);
//浅拷贝
let c = {...a}
let d = Object.assign({y:1},a)
console.log(d);